package com.example.permission.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.permission.service.ResourceService;
import com.example.platformsharedcommon.dict.resource.UserPlatform;
import com.example.platformsharedcommon.util.ResponseResult;

/**
 * 菜单
 * 
 * @author Dhjie
 *
 */
@RestController
public class ResourceController {
	private static final Logger logger = LoggerFactory.getLogger(RestController.class);
	@Autowired
	private ResourceService resourceService;

	/**
	 * 返回全部资源 分前后台
	 * 
	 * @return
	 */
	@GetMapping("allResources")
	public ResponseResult allResources() {
		try {
			return ResponseResult.ok(resourceService.allResources());
		} catch (Exception e) {
			logger.info(e.getMessage());
			return ResponseResult.error(e.getMessage());
		}
	}

	/**
	 * 根据角色获取获取资源菜单
	 * 
	 * @param roleIds
	 * @return
	 */
	@GetMapping("resourceByRole")
	public ResponseResult resourceByRole(@RequestParam("roleIds") String roleIds) {

		try {
			return ResponseResult.ok(resourceService.resourceByRole(roleIds,UserPlatform.MANAGE.getId()));
		} catch (Exception e) {
			logger.info(e.getMessage());
			return ResponseResult.error(e.getMessage());
		}
	}

}
